package net.wds.ssbus.modules.dict.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.wds.ssbus.modules.dict.entity.TbBaseDictEntity;
import net.wds.ssbus.modules.dict.entity.TbBaseDictitemEntity;
import net.wds.ssbus.modules.dict.po.TbBaseDictPo;
import net.wds.ssbus.modules.dict.service.TbBaseDictService;
import net.wds.ssbus.modules.dict.service.TbBaseDictitemService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

public class dictUtil {
    @Autowired
    TbBaseDictService tbBaseDictService;
    @Autowired
    TbBaseDictitemService tbBaseDictitemService;
    public void getTree(){
        List<TbBaseDictEntity> list = tbBaseDictService.list();
        List<TbBaseDictPo> collect = list.stream().map(item -> {
            TbBaseDictPo tbBaseDictPo = new TbBaseDictPo();
            BeanUtils.copyProperties(item, tbBaseDictPo);
            List<TbBaseDictitemEntity> dictitemEntities = tbBaseDictitemService.list(new QueryWrapper<TbBaseDictitemEntity>().eq("dict_code", item.getCode()));
            tbBaseDictPo.setChildren2(dictitemEntities);
            return tbBaseDictPo;
        }).collect(Collectors.toList());
        for (TbBaseDictPo s: collect){
            System.out.println(s.getDescription());
            System.out.println(s.getChildren2());
        }
    }
}
